package com.projects.api.module.demo.controller;

import com.projects.api.common.model.query.PageQuery;
import com.projects.api.common.model.result.ResultConstant;
import com.projects.api.common.model.result.ResultMsg;
import com.projects.api.common.model.result.ResultPage;
import com.projects.api.module.demo.entity.Demo;
import com.projects.api.module.demo.query.DemoQuery;
import com.projects.api.module.demo.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangzhenfu
 * @Description
 * @date 2022/8/14 0014 16:37
 */
@Api(tags = "示例表模块")
@RequestMapping("v1/api/core/system")
@RestController
@AllArgsConstructor
public class DemoController {

    private DemoService demoService;

    @ApiOperation("示例表-添加")
    @PostMapping("/Demo" )
    public ResultMsg<Demo> add(@RequestBody Demo form){
        //TODO 完成新增接口（字段校验参考表结构）
        return null;
    }

    @ApiOperation("示例表-删除")
    @DeleteMapping("/Demo/{id}" )
    public ResultMsg<Boolean> delete(@PathVariable Integer id){
        //TODO 完成删除接口
        return null;
    }

    @ApiOperation("示例表-修改")
    @PutMapping("/Demo/{id}" )
    public ResultMsg<Demo> update(@PathVariable Integer id, @RequestBody Demo form){
        //TODO 完成修改接口（字段校验参考表结构）
        return null;
    }

    @ApiOperation("示例表-详情")
    @GetMapping("/Demo/{id}" )
    public ResultMsg<Demo> detail(@PathVariable Integer id){
        //TODO 完成详情接口
        Demo demo = demoService.getDemo(id);
        return new ResultMsg(ResultConstant.SUCCESS,null,demo);
    }

    @ApiOperation("示例表-列表")
    @PutMapping("/Demo" )
    public ResultPage<Demo> list(@RequestBody DemoQuery query){
        //TODO 完成列表接口
        //数据查询
        List<Demo> list = demoService.queryDemo(query);
        /*
            组装返回参数
         */
        ResultPage<Demo> resultPage = new ResultPage<>();
        resultPage.setData(list);
        //TODO 完善分页返回参数，例如 totalPage （总页数）
        return resultPage;
    }
}
